<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //用一个数组表述它是否素数
    //埃筛法
    function fn(num) {
        let isPrime = new Array(num).fill(true)//true为素数
        let res = []
        isPrime[0] = false
        isPrime[1] = false
        for (let i = 2; i * i < num; i++) {
            if (isPrime[i]) {
                //找到所有能整除i的数字
                for (let j = i * i; j < num; j += i) {
                    isPrime[j] = false
                }
            }
        }
        for (let i = 2; i < num; i++) {
            if (isPrime[i]) res.push(i)

        }
        console.log(res, "-----");

    }
    fn(100)
</script>

</html>